package cn.ike.web.controller.system;

import cn.ike.domain.system.SysLog;
import cn.ike.service.system.SysLogService;
import cn.ike.web.controller.BaseController;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@Log4j
@RequestMapping("/system/log")
public class SysLogController extends BaseController {
    
    // 注入SysLogService
    @Autowired
    private SysLogService sysLogService;

    /**
     * 日志的分页查询
     */
    @RequestMapping("list")
    public ModelAndView list(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {
        ModelAndView model = new ModelAndView();
        try {
            log.info("执行日志的分页查询开始...");
            PageInfo<SysLog> pageInfo = sysLogService.findByPage(getLoginCompanyId(), pageNum, pageSize);
            model.addObject("pageInfo", pageInfo);
            model.setViewName("system/log/log-list");
            log.info("执行日志的分页查询结束...");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("执行日志的分页查询出现异常！", e);
        }
        return model;
    }
}
